package com.woniuxy.oldmanapi.mapper;

import com.woniuxy.oldmanapi.entity.Older;
import com.woniuxy.oldmanapi.xvo.OlderVo;
import org.apache.ibatis.annotations.Param;
import com.woniuxy.oldmanapi.yvo.OlderAndBedVo;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import org.apache.ibatis.annotations.Update;
import tk.mybatis.mapper.common.Mapper;

import java.util.Date;
import java.util.List;

@Repository
public interface OlderMapper extends Mapper<Older> {
    //查询所有老人信息
    List<OlderVo> selectOlderByCons(@Param("name") String name, @Param("status") int status, @Param("labelId") int labelId, @Param("careId") int careId);

    OlderVo selectOlderById(int id);

    List<OlderAndBedVo> initSelectOlderAndBedByCons(String name);

    List<OlderAndBedVo> selectOlderAndByBuildingAndStoreyAndRoomId(@Param("buildingId") int buildingId, @Param("storeyId") int storeyId, @Param("roomId") int roomId);


    @Update("update older set status = 0 , bed_id = null where id = #{id}")
    void updateOlderStatusById(int id);

    @Update("update older set status = 2 , exitDate = #{exitdate} where id = #{id}")
    void updateOlderStatusAndExitById(@Param("id") int id, @Param("exitdate") Date exitdate);

    List<Older> selectOlderByStatus(@Param("name") String name, @Param("status") int status);

    List<Integer> selectByCareIds(@Param("list") List<Integer> careIds);

    @Select("select * from older where care_id=#{id}")
    List<Older> selectByCareId(int id);

    OlderVo searchOlderByBid(int bedId);

    @Update("update older set bed_id = #{newbedId} where id = #{oid}")
    void updateOlderBed(@Param("oid") int oid, @Param("newbedId")int newbedId);

    @Update("update older set care_id = #{newcarId} where id = #{olderId}")
    void updateCareById(@Param("olderId") Integer olderId, @Param("newcarId") Integer newcareId);

    @Select("select count(id) from older where age >=#{little} and age <#{big}")
    int selectNumByOld(@Param("little") Integer little, @Param("big") Integer big);

    @Select("select count(id) from older WHERE YEAR(checkDate)=#{year} AND MONTH(checkDate)=#{month}")
    int selectOlderCheck(@Param("year") Integer year, @Param("month") Integer month);
}
